package com.tmxk.api.days01.Ysc;


import com.tmxk.api.days01.comm.Dog;

import java.util.HashSet;
import java.util.Iterator;
import java.util.TreeSet;

public class SetDemo {
    public static void main(String[] args) {
        Dog dog=new Dog("花花",2);
        Dog dog1=new Dog("花花",2);
        Dog dog2=new Dog("花花",2);
        Dog dog3=new Dog("花花",2);

        HashSet<Dog> dogSet=new HashSet<>();

        dogSet.add(dog);
        dogSet.add(dog1);
        dogSet.add(dog2);
        dogSet.add(dog3);

        System.out.println("dogset的长度"+dogSet.size());

        System.out.println("使用for循环遍历");
        for (Dog dog4:dogSet){
            System.out.println(dog4.getName()+"\t"+dog4.getAge()+"\t\t");
        }
        System.out.println("使用lambda表达式遍历");
        dogSet.forEach(dog4 -> {
            System.out.println(dog4.getName()+"\t"+dog4.getAge()+"\t\t");
        });

        Iterator<Dog>it=dogSet.iterator();
        while (it.hasNext()){
            Dog dog4=it.next();
            System.out.println(dog4.getName()+"\t"+dog4.getAge()+"\t\t");
        }
        TreeSet dogTreeSet=new TreeSet();

    }
}
